home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10509 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.std.c,com[p.lang.std.c++
  4. Subject: Re: preprocessing question
  5. Date: Thu, 07 Mar 1996 16:56:03 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <313EF903.1000@cmt.lpr.mail.carel.fi>
  8. References: <313b9e9f.480978@NEWS.CLOUD9.NET>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. John G. Alvord wrote:
  16. > I have a couple compilers argument about the following problem:
  17. >    #define XXX (1)
  18. >    #include <stdio.h>
  19. >    int main(void)
  20. >    {
  21. >        #if XXX
  22. >            printf("Hello World!");
  23. >        #endif
  24. >        return 0;
  25. >     }
  26. > most compilers I have tried preprocess the #if resulting in "#if (1)" and then
  27. > follow that instruction to generate the printf() call.
  28. > One compiler (SAS/C 5.50 cross compiler on AIX for MVS) complains that the #if
  29. > line is an illegal constant.  A close reading of the ANSI C standard document
  30. > reveals a clause that seems to imply (my reading) that a pre-processed series
  31. > of tokens that appear to be a preprocessing statement will be ignored. A
  32. > coworker who is more experienced then me feels that the #if does not fall
  33. > under that clause and the #if will be evaluated. His reasoning is that the
  34. > preprocessed series of tokens is just a part of a preprocessing statement.
  35. > If someone can shed some light on this, he would make me very happy.
  36. > Thanks!
  37. > John Alvord
  38.  
  39. Some (old?) preprocessors expect to find #xxx tokens starting at beginning of the 
  40. line. Also, there may be preprocessors that would want "#if conditional". If this is 
  41. the case, use
  42.  
  43.     #define    XXX    (1 == 1)
  44.  
  45. or use the convention
  46.  
  47.     #define    XXX
  48.     ...
  49.     #ifdef    XXX
  50.     ...
  51.     #endif
  52.  
  53. or, perhaps,
  54.  
  55.     #if defined XXX
  56.     ...
  57.     #endif
  58.  
  59. HTH,
  60.  AriL
  61. -- 
  62. All my opinions are mine and mine alone.
  63.